<?php 
class MY_Controller extends MX_Controller {
    public $userTheme ='default/';
    public  $language="vi";
	public $LoginData = NULL;
	private $errors = array();
	private $messages = array();
	public $_ci_view_paths=array();
    
	public $is_mobile = 0;
    
    function __construct()
    {
        parent::__construct();
		$this->is_mobile = $this->agent->is_mobile();
		$this->LoginData = $this->session->userdata('LoginData');
		
    }
    function index(){   
    }
	
	
	protected final function view($view_url, $data = NULL,$return = false,$layout = 'default') {
    	    	
    	$result = NULL;
        $data = (array) $data;
		  
        $data['userCurrentTheme'] = $this->userTheme;
		$data['LoginData'] = $this->LoginData;
		
		$data['lang_avail'] = $this->config->item('lang_avail');
		$data['lang_selected'] = $this->config->item('lang_selected');
		
		
		// set layout and partials                
		
		$this->template->set_theme($this->userTheme);
		$this->template->set_layout($layout);
		
		$this->template->set_partial('header','particles/common/header.php',$data);		
		$this->template->set_partial('footer','particles/common/footer.php',$data);
		
		$this->template->set_partial('navigation_path','particles/common/navigation_path.php', $data);
		
		$result = $this->template->build($view_url,$data,true);
            
        if($return){
        	return $result;
		}else{
			echo $result;	
		}
    }
	
	protected final function baseView($view_url, $data = NULL,$return = false,$layout = 'ajax') {
    	    	
    	$result = NULL;
        
        $data['LoginData'] = $this->LoginData;
		// set layout and partials                
		$this->template->set_theme($this->userTheme);
		$this->template->set_layout($layout);
		$result = $this->template->build($view_url, $data,TRUE);
            
       
         if($return){
        	return $result;
		}else{
			echo $result;	
		}
    }
	
	
	protected final function loginView($view_url, $data = NULL,$return = false,$layout = 'login') {
    	    	
    	$result = NULL;
        $data = (array) $data;
		  
        $data['userCurrentTheme'] = $this->userTheme;
		$data['LoginData'] = $this->LoginData;
		
		$data['lang_avail'] = $this->config->item('lang_avail');
		$data['lang_selected'] = $this->config->item('lang_selected');
		
		// set layout and partials                
		$this->template->set_theme($this->userTheme);
		$this->template->set_layout($layout);
		
		$this->template->set_partial('header','particles/login/lhead.php',$data);		
		$this->template->set_partial('footer','particles/login/lfooter.php',$data);
		
		$result = $this->template->build($view_url, $data,TRUE);            
       
        if($return){
        	return $result;
		}else{
			echo $result;	
		}
    }
	
	function loadModuleJs($jsFile){
		
		$module = $this->load->_module;		
		$script = "<script language=\"javascript\" src=\"".site_url("common/loadjs/".$module."/".$jsFile)."\"></script>";
		$this->template->append_metadata($script);
			
	}
	
	function loadModuleCss($cssFile){
		
		$module = $this->load->_module;		
		$cssLink = "<link rel=\"stylesheet\" href=\"".site_url("common/loadcss/".$module."/".$cssFile)."\">";
		$this->template->append_metadata($cssLink);
			
	}
	
	
	function set_error($error = '')
	{
		if ($error) $this->errors[] = $error;
	}
	
	function set_message($message = '')
	{
		if ($message) $this->messages[] = $message;
	}
	
	function display_errors()
	{
		$str = '';
		if (isset($this->errors) && count($this->errors)) {
			foreach ($this->errors as $error) {
				$str .= "<p class='error-message'>".$error.'</p>';
			}
		}
		return $str;
	}
	
	function display_messages()
	{
		$str = '';
		if (isset($this->messages) && count($this->messages)) {
			foreach ($this->messages as $msg) {
				$str .= "<p class='notice'>".$msg.'</p>';
			}
		}
		return $str;
	}
	
	function headerUTF8(){
		header('content-type: text/html; charset: utf-8');
	}
    
}
?>